<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>{if $siteName}{$siteName} - {/if}Режим администрирования</title>
	
	<link rel="stylesheet" type="text/css" href="css/cupertino/jquery-ui-1.8.16.custom.css">
	<link rel="stylesheet" type="text/css" href="css/main.css">
	<link rel="stylesheet" type="text/css" href="css/pine.css">
	<link rel="stylesheet" type="text/css" href="css/grid.css">
	
	<script type="text/javascript" src="../js/jquery.min.js"></script>
	<script type="text/javascript" src="../js/jquery-ui.min.js"></script>
	<script type="text/javascript" src="../js/jquery.ui.datepicker-ru.js"></script>
	<script type="text/javascript" src="../js/pine.js"></script>
	<script type="text/javascript" src="../js/smart.min.js"></script>
	<script type="text/javascript" src="../js/grid.js"></script>
	<script type="text/javascript" src="../js/php.default.namespaced.min.js"></script>
</head>
<body>
	{include 'grid.tpl'}

	<div id='waitBox' class='ui-state-highlight ui-corner-all'><span class="ui-icon ui-icon-info" style="float: left; margin-right: 5px;"></span><span>Ждите...</span></div>	
	<div id='msgbox'></div>
	
	<table id='all'>
		<tr>
			<td id='header' colspan=2>
				<span style='color: #0070A3; text-transform:uppercase; padding-left:3px;'>{if $siteName}<strong>{$siteName}</strong> - Режим администрирования{/if}</span>
				<div id='user'>
					<div class='ui-icon ui-icon-person'></div>
					<div id='uname'>{$user->name()}</div>
					<a href='login.php?logout' title='Выход'><div class='ui-icon ui-icon-power'></div>Выход</a>
				</div>
				<div class='clearFix'></div>
			</td>
		</tr>
		<tr>
			<td id='left'><div id='mainTree'></div></td>
			<td id='right'>
				<h1>{$name}</h1>
				<div class='breadcrumbs'>
					{if $tpl!='index.tpl'}<a href="/" class="ui-icon ui-icon-home"></a>{/if}
					{foreach $crumbs as $crumb}
						<span class="ui-icon ui-icon-carat-1-e"></span>
						{if $crumb@last}
							{$crumb[1]}
						{else}
							<a href="{$crumb[0]}">{$crumb[1]}</a>
						{/if}
					{/foreach}
				<div class="clearFix"></div>
				</div>
				
				{include $tpl}
			</td>
		</tr>
		<tr>
			<td id='footer' colspan=2>
			</td>
		</tr>
	</table>
	
	<script>
		var waitCount = 0;
		
		function call(url, params)
		{
			showWaitBox();
			return $.post('../call/'+url, params, function(data, textStatus, jqXHR) { hideWaitBox() }, 'json')
				.error( 
					function(jqXHR,textStatus,errorThrown) { 
						var sParams = '';
						for (var p in params) {
							sParams += ' ' + p + '=' + params[p];	//dump to string
						}
						/*
						alert('AJAX ERROR: url:'+
							url +
							'\nparams:'+
							sParams +
							'\nstatus: '+
							jqXHR.status
						);*/
				} );
		}
		
		function showWaitBox()
		{
			if (++waitCount==1) { $('#waitBox').show(); }
		}
		
		function hideWaitBox()
		{
			if (!--waitCount) { $('#waitBox').hide(); }
		}
		
		function confirmBox(txt, title, onOK)
		{
			$('#msgbox').html(txt).dialog( {
				modal: true,
				minWidth: 400,
				'title': title,
				buttons: { 
					'Отмена':function() { $(this).dialog('close'); }, 
					'OK': function() { $(this).dialog('close'); onOK(); }
				}
			} );
		}
		
		function errBox(txt, onClose)
		{
			var html = 
				'<div class="ui-state-error ui-corner-all" style="padding: 5px;"><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 5px;"></span>'+
				txt +
				'</div>';
			
			$('#msgbox').html(html).dialog( {
				modal: true,
				minWidth: 400,
				'title': 'Ошибка',
				close: function() { onClose(); },
				buttons: { 
					'Закрыть': function() { $(this).dialog('close'); }
				}
			} );
		}

		$( function() {
			$('#left').resizable( { 
				alsoResize: '#mainTree',
				handles: 'e',
				ghost: true,
				stop: function(e) { 
					call('session.set', { name:'mainTree_width', value:$('#mainTree').width() } );
				}
			} );
			
			call('session.get', { name:'mainTree_width' } ).done( function(width) {
				$('#mainTree').width(width)
			} );
			
			call('admin.getCategories').done( function (items) { 
				var t = new jPine($('#mainTree')[0], items);
				$.when(
					call('session.get', { name:'mainTree' } ),
					call('session.get', { name:'mainTreeCurrentItem' } )
				).done( function(states,currItem) {
					showWaitBox();
					t.setStates(states[0]);
					var item = t.findByID(currItem[0]);
					if (item) {
						$(item.els.name).addClass('activeItem');
					}
					hideWaitBox();
				} );
				t.onClick = function(item) {
					call('session.set', { name:'mainTreeCurrentItem', value:item.id } ).done( function() {
						if (item.properties.url) {
							window.location = item.properties.url;
						}
					} );
				}
				t.saveStates = function() {
					call('session.set', { name:'mainTree', value:this.getStates() } );
				}
				t.onToggle = function(item) {
					this.saveStates();
				}
			} );
		} );
	</script>
</body>
</html>